<!--工程划分-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked"  @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>

      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 部门信息 -->
      <div class="department_right_name">
        <div>{{ showName }}</div>
      </div>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left"></div>
        <!-- 右侧 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="getDataList(companyId)"
            ></el-button>
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <el-table
          ref="multipleTable"
          :data="tableData5"
          style="width: 100%"
          :height="navigatepageNums > 1 ? 'calc(100% - 20px)' : '100%'"
          border
          default-expand-all
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          row-key="F_CompanyId"
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
          @row-click="getRowInfo"
          highlight-current-row
          @current-change="rowChange"
          stripe
        >
          <el-table-column
            type="index"
            label="序号"
            width="50"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="F_CompanyId"
            label="工程编号"
          ></el-table-column>
          <el-table-column
            prop="F_ShortName"
            label="工程名称"
          ></el-table-column>
          <el-table-column prop="F_Nature" label="工程类别" width="90">
          </el-table-column>
          <el-table-column
            prop="isCous"
            label="工序报验总数(条)"
            width="120"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="oneCous"
            label="一次检验数(条)"
            width="110"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="moreCous"
            label="多次检验数(条)"
            width="110"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="price"
            label="一次性通过率"
            width="110"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="isHave"
            label="报验详情"
            width="90"
            align="center"
          >
            <template slot-scope="scope" v-if="scope.row.ischeck == 1">
              <el-button
                @click="openDialog(scope.row)"
                @cell-dblclick="openDialog"
                type="text"
                size="small"
              >
                查看
              </el-button>
            </template>
          </el-table-column>
          <template slot="empty">
            <img
              style="width: 285px; height: 208px"
              src="@/assets/img/undata.png"
              alt=""
            />
            <div class="pageFlagText">暂时没有数据哦！</div>
          </template>
        </el-table>
      </div>
    </div>
    <!-- 查看列表页 -->
    <div class="Control-1 mechanism_dialogS closure">
      <el-dialog
        title="详情列表"
        :modal-append-to-body="false"
        v-dialogDrag
        :visible.sync="dialogCheckVisible"
        v-loading="loadingCheckDialog"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
      >
        <div
          class="dialogBody common"
          :style="{ height: '650px' }"
          style="overflow: hidden"
        >
          <div
            style="
              overflow-y: auto;
              margin-bottom: 20px;
              background: pink;
              height: calc(100% - 31px);
            "
          >
            <tableData
              height="100%"
              :config="table_config1"
              :dataList="tableData1"
              :loading="loading"
              @click-change="rowChange1"
              @ClickOnLine="yj_viewForm"
            />
          </div>
        </div>
      </el-dialog>
    </div>

    <div class="Control-1 mechanism_dialogS closure">
      <el-dialog
        title="检验申请批复"
        :modal-append-to-body="false"
        v-dialogDrag
        :visible.sync="dialogEditVisible1"
        v-loading="loadingEditDialog1"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
      >
        <div
          class="dialogBody common"
          :style="{ height: '650px' }"
          style="overflow: hidden"
        >
          <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
          >
            <el-menu-item index="0">工程报验信息</el-menu-item>
            <el-menu-item index="1">报审流程查阅</el-menu-item>
          </el-menu>

          <div
            style="overflow-y: auto; margin-bottom: 20px; height: 100%"
            v-show="activeIndex == '0'"
          >
            <div class="publicForm" style="height: 225px; overflow-y: auto">
              <publicForm
                ref="publicForm"
                lableWidth="120px"
                :formObj="FromShow"
                :formData="formData1"
                :timestamp="formData1.fHandlefile"
                :fileList="fSourcefileList"
              >
              </publicForm>
            </div>
            <div class="baseTitle">监理员意见</div>
            <div class="publicForm" style="height: 120px; overflow-y: auto">
              <publicForm
                ref="publicForm0"
                lableWidth="120px"
                :formObj="putAway"
                :formData="formData1"
                :timestamp="formData1.fQualityfile"
                :fileList="fSourcefileList1"
              >
              </publicForm>
            </div>
            <div class="baseTitle">监理工程师审批</div>
            <div class="publicForm" style="height: 75px; overflow-y: auto">
              <publicForm
                ref="publicForm0"
                lableWidth="110px"
                :formObj="execute"
                :formData="formData1"
              >
              </publicForm>
            </div>
            <div class="baseTitle">施工单位签收</div>
            <div class="publicForm" style="height: 85px; overflow-y: auto">
              <publicForm
                ref="publicForm0"
                lableWidth="110px"
                :formObj="check"
                :formData="formData1"
              >
              </publicForm>
            </div>
            <!-- <div style="height: 50px"></div> -->
          </div>

          <div
            style="overflow-y: auto; margin-bottom: 20px; height: 100%"
            v-show="activeIndex == '1'"
          >
            <tableData
              height="100%"
              :config="table_configs"
              :dataList="tableDatas"
              :loading="loading"
            />
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  getUserCompanyTreeList, //机构树
  getWorkProcessProjectList, //列表页
  getWorkProcessList, //详情列表
  getWorkProcessDescriptionByFid, //详情表单
} from "@/api/request.js";
import tree from "@/components/QualityGridManage/tree"; //左侧机构树
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
export default {
  data() {
    return {
      name: "stationWorkList",
      navigatepageNums: null,
      row: {},
      showName: "未选择公司",
      checked: false, //查看下级
      fId: null, //当前数据fId
      loading: false,
      tableData5: [],
      formData: {},
      treeData: [],
      tableData: [],
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      companyId: null,
      treeText: {
        companyId: null,
        userId: null,
      },
      treelength: false,
      checkData: [],

      // 详情
      table_config1: formJs.table_config1, //列表
      row1: {}, //工作指令---选中行
      dialogCheckVisible: false,
      loadingCheckDialog: false,
      tableData1: [], //指令列表数据列表
      formData1: formJs.formData,
      loadingEditDialog1: false, //弹框loading
      dialogEditVisible1: false, //新增弹框是否显示
      // 详情弹框
      FromShow: formJs.FromShowLook, //信息查看配置参数
      putAway: formJs.putAwayLook,
      execute: formJs.executeLook,
      check: formJs.checkLook,
      fSourcefileList1: [],
      fSourcefileList: [],
      activeIndex:"0",

      table_configs: formJs.table_configs, //列表
      tableDatas: [],
      // 详情弹框

      // 详情
    };
  },
  components: {
    tree,
    TableData, //主页面列表
    publicForm, //弹框表格
    // Pagination, //分页
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
    if (JSON.parse(sessionStorage.getItem("yjSmart-Quality_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("yjSmart-Quality_treeCheck"));
      this.checkData = [id.fCompanyid];
    }

    this.getTree();
  },
  methods: {
    // 左侧树结构
    getTree() {
      this.treeText.companyId = this.userInfo.companyId;
      this.treeText.userId = this.userInfo.userId;
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false;
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-Quality_treeCheck")
              ).fShortname;
              this.companyId = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
              this.checkData[0] = this.treeData[0].fCompanyid;
            }
            // 列表
            this.getDataList(this.companyId);
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    tranListToTreeData1(data) {
      let result = [];
      if (!Array.isArray(data)) {
        return result;
      }
      // 清除已存在的children 重新赋值
      data.forEach((item) => {
        delete item.children;
      });

      let map = {};
      data.forEach((item) => {
        map[item.F_CompanyId] = item;
      });

      data.forEach((item) => {
        let parent = map[item.F_ParentId];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });

      return result;
    },
    // 获取列表数据
    getDataList(id) {
      getWorkProcessProjectList({ companyId: id })
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            setTimeout(() => {
              that.loading = false;
              that.tableData5 = this.tranListToTreeData1(
                res.data.workProcessProjectList
              );
              this.navigatepageNums = that.tableData5.length;
              // that.$nextTick(() => {
              //   that.$refs.multipleTable.doLayout();
              // });
            }, 200);
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 点击当前行
    getRowInfo(e) {
      this.fId = e.F_EnCode;
      this.row = e;
    },
    //点击当前行变色
    rowChange() {},
    //点击树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getDataList(data.fCompanyid);
    },
    //点击查看
    openDialog(row) {
      this.row = row;
      this.dialogCheckVisible = true;
      this.yj_searchForm(row.F_EnCode);
    },

    // 详情
    yj_searchForm(id) {
      this.loadingCheckDialog = true;
      getWorkProcessList({
        enCode: id,
      })
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loadingCheckDialog = false;
            that.tableData1 = res.data.WorkProcessLists;
          } else {
            this.$message.error("列表", res.msg);
            this.loadingCheckDialog = false;
          }
        })
        .catch(() => {
          this.loadingCheckDialog = false;
          console.log("详情列表页报错");
        });
    },
    rowChange1(val) {
      this.row1 = val;
    },
    yj_viewForm(row, label) {
      this.row1 = row;
      if (label == "报验单编号") {
        this.editText(row.fId);
      }
    },
    editText(id) {
      if (id != "" && id != null) {
        this.loadingEditDialog1 = true; //弹框loading
        this.dialogEditVisible1 = true;
        getWorkProcessDescriptionByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loadingEditDialog1 = false;
              this.formData1 = res.data.WorkprocessDescription;
              this.fSourcefileList = res.data.fHandlefileList; //附件资料
              this.fSourcefileList1 = res.data.fQualityfileList; //执行报告附件材料
              this.tableDatas = res.data.WorkprocessChecklogs;
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog1 = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog1 = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
    handleSelect(key) {
      this.activeIndex = key;
    },
    // 详情
  },
};
</script>

<style scoped>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.pageFlagText {
  color: #171a1d;
  font-size: 16px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
/* 弹框 */
.common /deep/.el-menu--horizontal > .el-menu-item.is-active {
  color: #409eff !important;
}
.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 125px !important;

}
/* 弹框 */
</style>